﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using IBatisNet.DataMapper;
using TumbaloSoft.Helpers.QueryObjects;
using TumbaloSoft.Models;

namespace TumbaloSoft.Helpers
{
    public class HelperReservaAreaComun
    {
        public static int insert(TumbaloSoft.Models.ReservaAreaComun reservaAreaComun)
        {
            Mapper.Instance().Insert("ReservaAreaComunInsert", reservaAreaComun);
            return 0;
        }
        public static void delete(TumbaloSoft.Models.ReservaAreaComun reservaAreaComun)
        {
            Mapper.Instance().Update("ReservaAreaComunDelete",reservaAreaComun);
        }

        public static ReservaAreaComun selectById(int id)
        {
            IList reservas = Mapper.Instance().QueryForList("ReservaAreaComunSelectById", id);
            if (reservas.Count == 0) return null;
            ReservaAreaComun reserva = (ReservaAreaComun)(reservas[0]);
            reserva.prEdificio = HelperEdificio.selectById(reserva.prEdificio.prIdEdificio);
            reserva.prAreaComun = HelperAreaComun.selectById(reserva.prAreaComun.prIdAreaComun);
            return reserva;
        }

        public static IList selectAll()
        {
            return Mapper.Instance().QueryForList("ReservaAreaComunSelectAll", null);       
        }

        public static int selectMaxCodigo()
        {
            return (int)Mapper.Instance().QueryForObject("ReservaAreaComunSelectMaxCodigo", null);
        }

        /*public static IList buscar(BusquedaReservaAreaComun ReservaAreaComunBuscar)
        {
            return Mapper.Instance().QueryForList("EdificioBuscar", ReservaAreaComunBuscar);
        }*/

        public static List<ReservaAreaComun> selectFuturosByIdAreaComun(int idAreaComun)
        {
            IList lista = Mapper.Instance().QueryForList("ReservaAreaComunSelectFuturosByIdAreaComun", idAreaComun);
            return new List<ReservaAreaComun>(lista.Cast<ReservaAreaComun>());
        }

        public static int selectCountActivos()
        {
            return (int)Mapper.Instance().QueryForObject("ReservaAreaComunSelectCountActivos", null);
        }

        public static List<ReservaAreaComun> selectByIdPropietario(int idPropietario)
        {
            IList lista = Mapper.Instance().QueryForList("ReservaAreaComunSelectByIdPropietario", idPropietario);
            return new List<ReservaAreaComun>(lista.Cast<ReservaAreaComun>());
        }

    }
}